import * as XLSX from 'xlsx'
import axios from "axios"
axios.defaults.baseURL = '/api'

export function readExcelFile(url) {
  axios.get(url, { responseType: 'arraybuffer' })
    .then((res) => {
      let data = new Uint8Array(res.data)
      let wb = XLSX.read(data, { type: "array" })
      let sheets = wb.Sheets
      transformSheets(sheets)
    }).catch(err => {
      console.log(err)
    })
}

export function transformSheets(sheets) {
  let content1 = [];
  let tmplist = [];
  for (let key in sheets) {
    tmplist.push(XLSX.utils.sheet_to_json(sheets[key].length))
    content1.push(XLSX.utils.sheet_to_json(sheets[key]))
  };
  console.log(tmplist);
  console.log(content1);
}